<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单编号">
              <a-input placeholder="请输入订单编号" v-model="queryParam.orderNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务名称">
              <a-input placeholder="请输入任务名称" v-model="queryParam.taskName"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户名称">
                <a-input placeholder="请输入客户名称" v-model="queryParam.customerName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="商务人员">
                <j-select-user-by-dep placeholder="请选择商务人员" v-model="queryParam.businessPerson"/>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="8" :sm="24">
              <a-form-item label="下单时间">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.orderTime_begin" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.orderTime_end" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="货款状态">
                <j-dict-select-tag placeholder="请选择货款状态" v-model="queryParam.paymentStatus" dictCode="payment_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('订单管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
         <a @click="handleDetail(record)">详情</a>
         <template v-if="record.bpmStatus !== '1'">
           <a-divider type="vertical"/>
           <a @click="handleProcessTrack(record)">流程跟踪</a>
         </template>
        </span>

      </a-table>
    </div>

    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="订单入账金额" key="1" >
        <YjOrderPaymentList :mainId="selectedMainId" />
      </a-tab-pane>
    </a-tabs>

    <yjOrder-modal ref="modalForm" @ok="modalFormOk"></yjOrder-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import YjOrderModal from '.././modules/YjOrderModal'
  import { getAction } from '@/api/manage'
  import YjOrderPaymentList from './YjOrderPaymentList'
  import { initDictOptions, filterMultiDictText, filterDictText } from '@/components/dict/JDictSelectUtil'
  import BpmProcessTrackModal from '@views/modules/bpmbiz/common/BpmProcessTrackModal.vue'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "YjOrderList_Payment",
    mixins:[JeecgListMixin],
    components: {
      BpmProcessTrackModal,
      YjOrderPaymentList,
      YjOrderModal
    },
    data () {
      return {
        description: '订单管理管理页面',
        // 表头
        columns: [
          {
            title:'订单编号',
            align:"center",
            dataIndex: 'orderNo'
          },
          {
            title:'流程状态',
            align:"center",
            dataIndex: 'bpmStatus',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.bpmStatusDictOptions, text)
            }
          },
          {
            title:'任务名称',
            align:"center",
            dataIndex: 'taskName'
          },
          {
            title:'客户名称',
            align:"center",
            dataIndex: 'customerName'
          },
          {
            title:'客户电话',
            align:"center",
            dataIndex: 'customerPhone'
          },
          {
            title:'客户税号',
            align:"center",
            dataIndex: 'customerTaxId'
          },
          {
            title:'实际金额',
            align:"center",
            dataIndex: 'actualAmount'
          },
          {
            title:'设计金额',
            align:"center",
            dataIndex: 'designAmount'
          },
          {
            title:'首付款',
            align:"center",
            dataIndex: 'downPayment'
          },
          {
            title:'已收金额',
            align:"center",
            dataIndex: 'receivedAmount'
          },
          {
            title:'未收金额',
            align:"center",
            dataIndex: 'unpaidAmount'
          },
          {
            title:'下单时间',
            align:"center",
            dataIndex: 'orderTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'交付时间',
            align:"center",
            dataIndex: 'requiredDeliveryTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'总工期/天',
            align:"center",
            dataIndex: 'totalDays'
          },
          {
            title:'单子类型',
            align:"center",
            dataIndex: 'orderType_dictText',
          },
          {
            title:'货款状态',
            align:"center",
            dataIndex: 'paymentStatus_dictText',
          },
          {
            title:'商务人员',
            align:"center",
            dataIndex: 'businessPerson_dictText'
          },
          {
            title:'当前状态',
            align:"center",
            dataIndex: 'currentStatus'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/erp/yjOrderPaymentList/list",
          delete: "/erp/yjOrderPaymentList/delete",
          deleteBatch: "/erp/yjOrderPaymentList/deleteBatch",
          exportXlsUrl: "/erp/yjOrderPaymentList/exportXls",
          importExcelUrl: "erp/yjOrderPaymentList/importExcel",
        },
        dictOptions:{
         orderType:[],
         paymentStatus:[],
         deliveryMethod:[],
        },
        flowCode: 'onl_yj_order',
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      handleProcessTrack: function(record){
        var params = {
          flowCode: this.flowCode,
          dataId: record.id
        };
        this.$refs.bpmProcessTrackModal.handleTrack(params);
      },
      initDictConfig(){
        //初始化字典
        initDictOptions('bpm_status').then((res) => {
          if (res.success) {
            this.bpmStatusDictOptions = res.result;
          }
        });
        initDictOptions('order_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'orderType', res.result)
          }
        })
        initDictOptions('payment_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'paymentStatus', res.result)
          }
        })
        initDictOptions('delivery_method').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'deliveryMethod', res.result)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'bpmStatus',text:'流程状态',dictCode:'bpm_status'})
        fieldList.push({type:'string',value:'orderNo',text:'订单编号',dictCode:''})
        fieldList.push({type:'string',value:'taskName',text:'任务名称',dictCode:''})
        fieldList.push({type:'string',value:'customerName',text:'客户名称',dictCode:''})
        fieldList.push({type:'string',value:'customerPhone',text:'客户电话',dictCode:''})
        fieldList.push({type:'string',value:'customerTaxId',text:'客户税号',dictCode:''})
        fieldList.push({type:'string',value:'orderModel',text:'订单模型',dictCode:''})
        fieldList.push({type:'Text',value:'orderImages',text:'订单图片',dictCode:''})
        fieldList.push({type:'int',value:'modelCount',text:'模型数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'modelWeight',text:'模型克重',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'machineWeight',text:'上机克重',dictCode:''})
        fieldList.push({type:'string',value:'quotePerGram',text:'单克金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'estimatedAmount',text:'预估金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'actualAmount',text:'实际金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'designAmount',text:'设计金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'receivedAmount',text:'已收金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'unpaidAmount',text:'未收金额',dictCode:''})
        fieldList.push({type:'date',value:'orderTime',text:'下单时间'})
        fieldList.push({type:'date',value:'requiredDeliveryTime',text:'交付时间'})
        fieldList.push({type:'string',value:'totalDays',text:'总工期/天',dictCode:''})
        fieldList.push({type:'Text',value:'customerRequirements',text:'客户要求',dictCode:''})
        fieldList.push({type:'string',value:'orderType',text:'单子类型',dictCode:'order_type'})
        fieldList.push({type:'string',value:'paymentStatus',text:'货款状态',dictCode:'payment_status'})
        fieldList.push({type:'string',value:'deliveryMethod',text:'发货方式',dictCode:'delivery_method'})
        fieldList.push({type:'sel_user',value:'businessPerson',text:'商务人员'})
        // fieldList.push({type:'string',value:'currentStatus',text:'当前状态',dictCode:''})
        // fieldList.push({type:'Text',value:'remarks',text:'备注',dictCode:''})
        // fieldList.push({type:'Text',value:'issues',text:'存在问题点',dictCode:''})
        // fieldList.push({type:'date',value:'designPlannedStart',text:'设计计划开始时间'})
        // fieldList.push({type:'date',value:'designPlannedEnd',text:'设计计划结束时间'})
        // fieldList.push({type:'date',value:'designActualEnd',text:'设计实际交付时间'})
        // fieldList.push({type:'BigDecimal',value:'designActualHours',text:'设计实际工时(小时)',dictCode:''})
        // fieldList.push({type:'string',value:'designSignature',text:'设计签字',dictCode:''})
        // fieldList.push({type:'Text',value:'designRemarks',text:'设计备注',dictCode:''})
        // fieldList.push({type:'Text',value:'designProgressTracking',text:'设计节点进度跟进',dictCode:''})
        // fieldList.push({type:'date',value:'businessPlannedStart',text:'商务确认计划开始时间'})
        // fieldList.push({type:'date',value:'businessPlannedEnd',text:'商务确认计划结束时间'})
        // fieldList.push({type:'date',value:'businessActualConfirm',text:'商务实际确认时间'})
        // fieldList.push({type:'BigDecimal',value:'businessActualHours',text:'商务实际工时(小时)',dictCode:''})
        // fieldList.push({type:'string',value:'businessSignature',text:'商务签字',dictCode:''})
        // fieldList.push({type:'Text',value:'businessRemarks',text:'商务备注',dictCode:''})
        // fieldList.push({type:'date',value:'programmingPlannedStart',text:'编程计划开始时间'})
        // fieldList.push({type:'date',value:'programmingPlannedEnd',text:'编程计划结束时间'})
        // fieldList.push({type:'date',value:'programmingActualEnd',text:'编程实际交付时间'})
        // fieldList.push({type:'BigDecimal',value:'programmingActualHours',text:'编程实际工时(小时)',dictCode:''})
        // fieldList.push({type:'string',value:'programmingSignature',text:'编程签字',dictCode:''})
        // fieldList.push({type:'Text',value:'programmingRemarks',text:'编程备注',dictCode:''})
        // fieldList.push({type:'Text',value:'programmingProgressTracking',text:'编程节点进度跟进',dictCode:''})
        // fieldList.push({type:'date',value:'productionPlannedStart',text:'生产计划开始时间'})
        // fieldList.push({type:'date',value:'productionPlannedEnd',text:'生产计划结束时间'})
        // fieldList.push({type:'date',value:'productionActualEnd',text:'生产实际交付时间'})
        // fieldList.push({type:'BigDecimal',value:'productionActualHours',text:'生产实际总工时(小时)',dictCode:''})
        // fieldList.push({type:'string',value:'productionSignature',text:'生产签字',dictCode:''})
        // fieldList.push({type:'Text',value:'productionRemarks',text:'生产备注',dictCode:''})
        // fieldList.push({type:'Text',value:'productionProgressTracking',text:'生产节点进度跟进',dictCode:''})
        // fieldList.push({type:'BigDecimal',value:'designDurationRatio',text:'设计工期占比(≤30%)',dictCode:''})
        // fieldList.push({type:'BigDecimal',value:'businessDurationRatio',text:'商务工期占比(≤10%)',dictCode:''})
        // fieldList.push({type:'BigDecimal',value:'programmingDurationRatio',text:'编程工期占比(≤30%)',dictCode:''})
        // fieldList.push({type:'BigDecimal',value:'productionDurationRatio',text:'生产工期占比(≥30%)',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>